﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CS3230HealthTrackerSystemGUI
{
    /// <summary>
    /// @Author: Chase Cole
    /// @Version: 11/7/2011
    /// 
    /// Decryption class is a small keyholder class which can generate connection strings 
    /// using encyrpted information that adheres to the correct formula. 
    /// </summary>
    class Decryption
    {
        /// <summary>
        /// Returns the complete connection string after being decrypted.
        /// </summary>
        /// <param name="database">The encyprted database name.</param>
        /// <param name="UID">The encrypted userID.</param>
        /// <param name="password">The encrypted password.</param>
        /// <returns>The connnection string.</returns>
        public string returnConnectionString(string database, string UID, string password)
        {
            String connectionString = " ";
            connectionString = decryptConnectionString(database, UID, password);
            return connectionString;
        }

        // <summary>
        // Returns the complete connection string after being decrypted.
        // </summary>
        // <param name="database">The encyprted database name.</param>
        // <param name="UID">The encrypted userID.</param>
        // <param name="password">The encrypted password.</param>
        // <returns>The connnection string.</returns>
        private string decryptConnectionString(string database, string UID, string password)
        {
            return "DRIVER={MySQL ODBC 5.1 Driver};" +
                      "SERVER=cs.westga.edu;" +
                      "PORT=3307;" +
                      "DATABASE=" + returnKey(database) + ";" +
                      "UID=" + returnKey(UID) + ";" +
                      "PASSWORD=" + returnKey(password) + ";";

        }

        /// <summary>
        /// Returns the decypted string of individual parts of data.
        /// </summary>
        /// <param name="data">The data to decypt.</param>
        /// <returns>The string after decryption.</returns>
        public string returnKey(string data)
        {
            data = decryptKey(data);
            return data;
        }

        // <summary>
        // The decyprtion algorithim.
        // Returns the decypted string of individual parts of data.
        // </summary>
        // <param name="data">The data to decypt.</param>
        // <returns>The string after decryption.</returns>
        private string decryptKey(String data)
        {
            data = data.Replace("x", "c");
            data = data.Replace("j", "o");
            data = data.Replace("r", "l");
            data = data.Replace("m", "e");
            data = data.Replace("y", "5");
            data = data.Replace("3", "@");
            data = data.Replace("k", "6");
            data = data.Replace("z", "0");
            data = data.Replace("4", "7");
            return data;
        }
    }
}
